package com.zlf.sb.demo.controller;


import com.zlf.sb.demo.design.factory.ContractStatusEnum;
import com.zlf.sb.demo.design.factory.SceneHandleBase;
import com.zlf.sb.demo.design.factory.SceneHandleFactory;
import com.zlf.sb.demo.dto.ContractEvent;
import com.zlf.sb.demo.dto.TResult;
import com.zlf.sb.demo.dto.UserEntityDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


/**
 * 示例前端请求控制器
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class FactoryController {
    @Autowired
    private SceneHandleFactory sceneHandleFactory;


    @GetMapping("/event")
    public void event() throws IOException {
        ContractEvent contractEvent = new ContractEvent();
        contractEvent.setStatus("CLOSED");
        SceneHandleBase<UserEntityDto, ContractEvent, TResult<Boolean>> statusHandle = sceneHandleFactory.getSceneHandle(ContractStatusEnum.valueOf(contractEvent.getStatus()), null);

        TResult<Boolean> res = statusHandle.doCallback(contractEvent);
        System.out.println("res = " + res);
    }


}
